package com.fanyue.modules.wzb.utils;


import cn.hutool.http.ContentType;
import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSON;
import com.fanyue.core.request.R;
import lombok.extern.slf4j.Slf4j;
/*
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
*/

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

//调用人脸验证接口
@Slf4j
public class FaceApiUtils {

	//根据不同的平台id 访问不同的API
	//public static String url = "http://casiku.i996.me";  //
	public static String urlPath = "http://127.0.0.1:8002";  //

	public static String extract(Long userId, File file) throws Exception {
		HttpResponse response = HttpRequest.post(urlPath + "/face/extract/feature")
				.header(Header.CONTENT_TYPE, ContentType.MULTIPART.getValue())
				.timeout(30000)
				.form("userId", userId)
				.form("faceFile", file)
				.execute();
		String result = response.body();
		return result;
	}

	public static String compare(String featureData) throws Exception {
		Map<String,Object> m = new HashMap<>();
		m.put("featureData",featureData);
		String result = HttpRequest.post(urlPath + "/face/compare/feature")
				.body(JSONUtil.toJsonStr(m))
				.execute().body();
//				.header(Header.CONTENT_TYPE, ContentType.MULTIPART.getValue())
//				.timeout(30000)
//				.form("featureData", featureData)
//				.execute();
//		String result = response.body();
		return result;
	}

	public static String delete(Map<String,Object> param) throws Exception {
		return HttpRequest.post(urlPath + "/face/delete/feature")
				.body(JSONUtil.toJsonStr(param))
				.execute().body();
	}

	public static void main(String[] args) {
		long b = 1739419773308L + 180L * 24 * 60 * 60 * 1000;
		long a = new Date().getTime();
		if (a > b) {
			System.out.println("aaaaa");
		}
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("userId", "");
		map.put("faceFile", "");
		try {
			//System.out.println(face(map));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
